<demo>
支持单文件、多文件上传
</demo>
<template>
  <div>
    <Uploader
      action="https://node-server-hsy.herokuapp.com/upload"
      name="file"
      v-model:fileList="fileList"
      @error="alert"
      :parseResponse="parseResponse"
    >
      <Button level="main">上传</Button>
    </Uploader>
    <div>只能上传JPG/PNG文件</div>
  </div>
</template>

<script lang="ts">
import { ref } from 'vue'
import Button from '../../lib/Button.vue'
import Uploader from '../../lib/Uploader.vue'
export default {
  components: {
    Button,
    Uploader,
  },
  setup(props) {
    let url = ref('about:blank')
    let fileList = ref([])
    const parseResponse = (response) => {
      let object = JSON.parse(response)
      url.value = `https://node-server-hsy.herokuapp.com/upload/${object.id}`
      return url
    }

    const addFile = (file) => {
      fileList.value.push(file)
    }

    return {
      fileList,
      parseResponse,
      alert,
    }
  },
}
</script>

<style lang="scss"></style>
